﻿/****************************** 模块头 ******************************\
* 模块名:  Message.cs
* 项目名:  DingTalkAPIHelp
* 版权(c)  auth markeluo.
* 
*说明： Message 用于调用钉钉API 消息相关接口
* This source is subject to the markeluo
* All other rights reserved.
\***************************************************************************/

using DingTalk.Api;
using DingTalk.Api.Request;
using DingTalk.Api.Response;
using DingTalkAPIHelp.Base;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DingTalkAPIHelp.Message
{
    /// <summary>
    /// 消息管理
    /// </summary>
    public class MessageManager:SysConfigManager
    {
        private static MessageManager manager = new MessageManager();
        /// <summary>
        /// 消息管理实例(单例)
        /// </summary>
        public static MessageManager Instance
        {
            get
            {
                return manager;
            }
        }

        #region 1.群消息
       /// <summary>
        /// 1.1.会话-创建
       /// </summary>
       /// <param name="groupName">群名称</param>
       /// <param name="ownerUserId">群主</param>
       /// <param name="userIdList">群成员UserId列表</param>
        /// <param name="showHistoryType">新成员是否可查看聊天历史消息0代表否，1代表是，不传默认为否</param>
        public OapiChatCreateResponse ChatCreate(string groupName, string ownerUserId, List<string> userIdList, long showHistoryType)
        {
            IDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/chat/create");
            
            OapiChatCreateRequest request = new OapiChatCreateRequest();
            request.Name = groupName;
            request.Owner = ownerUserId;
            request.Useridlist = userIdList;
            request.ShowHistoryType = showHistoryType;

            OapiChatCreateResponse response = client.Execute(request, accessToken);
            return response;
        }

        /// <summary>
        /// 1.2.会话-修改
        /// </summary>
        /// <param name="chatId">会话Id</param>
        /// <param name="groupName">群名称-非必须,为空则不修改</param>
        /// <param name="ownerUserId">群主UserId-非必须,为空则不修改</param>
        /// <param name="addUserIdList">添加用户Id-非必须,为空则不修改</param>
        /// <param name="delUserIdList">移除用户Id-非必须,为空则不修改</param>
        public OapiChatUpdateResponse ChatUpdate(string chatId, string groupName, string ownerUserId, List<string> addUserIdList, List<string> delUserIdList)
        {
            IDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/chat/update");
            OapiChatUpdateRequest request = new OapiChatUpdateRequest();
            request.Chatid = chatId;
            if (!string.IsNullOrWhiteSpace(groupName))
            {
                request.Name = groupName;
            }
            if (!string.IsNullOrWhiteSpace(ownerUserId))
            {
                request.Owner = ownerUserId;
            }
            if (addUserIdList != null && addUserIdList.Count > 0)
            {
                request.AddUseridlist = addUserIdList;
            }
            if (delUserIdList != null && delUserIdList.Count > 0)
            {
                request.DelUseridlist = delUserIdList;
            } 
            OapiChatUpdateResponse response = client.Execute(request, accessToken);
            return response;
        }

        /// <summary>
        /// 1.2.会话-详情-根据Id获取
        /// </summary>
        /// <param name="chatId"></param>
        public OapiChatGetResponse ChatDetail(string chatId)
        {
            IDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/chat/get");
            OapiChatGetRequest request = new OapiChatGetRequest();
            request.SetHttpMethod("GET");
            request.Chatid = chatId;
            OapiChatGetResponse response = client.Execute(request, accessToken);
            return response;
        }

        /// <summary>
        /// 1.3.群消息-发送消息 (仅限)文本/图片/文件
        /// </summary>
        /// <param name="chatId">会话ID</param>
        /// <param name="messageType">消息类型 (仅限)文本/图片/文件</param>
        /// <param name="Content">内容</param>
        public OapiChatSendResponse ChatSendMessage(string chatId,MessageType messageType,string Content)
        { 
            OapiChatSendRequest request = new OapiChatSendRequest();
            request.Chatid = chatId;
            request.Msgtype=messageType.ToString();
            switch (messageType)
            { 
                case MessageType.text:
                    OapiChatSendRequest.TextDomain _text = new OapiChatSendRequest.TextDomain();
                    _text.Content = Content;
                    request.Text_ = _text;
                    break;
                case MessageType.image:
                    OapiChatSendRequest.ImageDomain _image = new OapiChatSendRequest.ImageDomain();
                    _image.MediaId = Content;
                    request.Image_ = _image;
                    break;
                case MessageType.file:
                    OapiChatSendRequest.FileDomain _file = new OapiChatSendRequest.FileDomain();
                    _file.MediaId = Content;
                    request.File_ = _file;
                    break;
                default:
                    break;
            }
             
            OapiChatSendResponse response =SendChatMessage(request);
            return response;
        }
        /// <summary>
        /// 1.4.群消息-发送链接消息
        /// </summary>
        /// <param name="chatId"></param>
        /// <param name="Title"></param>
        /// <param name="Text"></param>
        /// <param name="MessageUrl"></param>
        /// <param name="PicUrl"></param>
        public OapiChatSendResponse ChatSendMessage(string chatId,string Title, string Text, string MessageUrl, string PicUrl)
        {
            OapiChatSendRequest request = new OapiChatSendRequest();
            request.Chatid = chatId;
            request.Msgtype = "link";

            OapiChatSendRequest.LinkDomain _link = new OapiChatSendRequest.LinkDomain();
            _link.Title = Title;
            _link.Text = Text;
            _link.MessageUrl = MessageUrl;
            _link.PicUrl = PicUrl;
            request.Link_ = _link;

            OapiChatSendResponse response = SendChatMessage(request);
            return response;
        }
        /// <summary>
        ///  1.4.群消息-发送markdown
        /// </summary>
        /// <param name="chatId"></param>
        /// <param name="Title"></param>
        /// <param name="Text"></param>
        public OapiChatSendResponse ChatSendMessage(string chatId, string Title, string Text)
        {
            OapiChatSendRequest request = new OapiChatSendRequest();
            request.Chatid = chatId;
            request.Msgtype = "markdown";

            OapiChatSendRequest.MarkdownDomain _markdown = new OapiChatSendRequest.MarkdownDomain();
            _markdown.Title = Title;
            _markdown.Text = Text;
            request.Markdown_ = _markdown;

            OapiChatSendResponse response = SendChatMessage(request);
            return response;
        }

        /// <summary>
        /// 1.5.群消息-发送OA表单
        /// </summary>
        /// <param name="chatId">会话ID</param>
        /// <param name="MessageUrl">详情跳转url</param>
        /// <param name="PcMessageUrl">PC端跳转H5地址</param>
        /// <param name="Head">消息头</param>
        /// <param name="Body">消息体</param>
        /// <returns></returns>
        public OapiChatSendResponse ChatSendMessage(string chatId, string MessageUrl, string PcMessageUrl,
            OapiChatSendRequest.HeadDomain Head, OapiChatSendRequest.BodyDomain Body)
        {
            OapiChatSendRequest request = new OapiChatSendRequest();
            request.Chatid = chatId;
            request.Msgtype = "oa";

            OapiChatSendRequest.OaDomain _oa = new OapiChatSendRequest.OaDomain();
            _oa.MessageUrl = MessageUrl;
            _oa.PcMessageUrl = PcMessageUrl;
            _oa.Head = Head;
            _oa.Body = Body;

            request.Oa_ = _oa;

            OapiChatSendResponse response = SendChatMessage(request);
            return response;
        }

        /// <summary>
        ///  1.6.群消息-整体跳转卡片
        /// </summary>
        /// <param name="chatId">会话id</param>
        /// <param name="Title">标题</param>
        /// <param name="Markdown">内容</param>
        /// <param name="SingleTitle">使用整体跳转ActionCard样式时的标题</param>
        /// <param name="SingleUrl">跳转地址</param>
        /// <param name="agentId">应用id，可选</param>
        /// <returns></returns>
        public OapiChatSendResponse ChatSendMessage(string chatId, string Title, string Markdown, string SingleTitle, string SingleUrl,string agentId)
        {
            OapiChatSendRequest request = new OapiChatSendRequest();
            request.Chatid = chatId;
            request.Msgtype = "action_card";

            OapiChatSendRequest.ActionCardDomain _card = new OapiChatSendRequest.ActionCardDomain();
            _card.Title = Title;
            _card.Markdown = Markdown;
            _card.SingleTitle = SingleTitle;
            _card.SingleUrl = SingleUrl;
            if (!string.IsNullOrWhiteSpace(agentId))
            {
                _card.Agentid = agentId;
            }
            else
            {
                _card.Agentid = AgentId.ToString();
            }

            request.ActionCard_ = _card;

            OapiChatSendResponse response = SendChatMessage(request);
            return response;
        }

        /// <summary>
        /// 1.7.群消息-独立跳转卡片
        /// </summary>
        /// <param name="chatId">会话id</param>
        /// <param name="Title">标题</param>
        /// <param name="Markdown">内容</param>
        /// <param name="BtnOrientation">独立跳转按钮排列方式，竖直排列(0)，横向排列(1)</param>
        /// <param name="BtnJsonList">按钮列表</param>
        /// <param name="agentId">应用Id，可选</param>
        /// <returns></returns>
        public OapiChatSendResponse ChatSendMessage(string chatId, string Title, string Markdown,
            string BtnOrientation, List<OapiChatSendRequest.BtnJsonDomain> BtnJsonList, string agentId)
        {
            OapiChatSendRequest request = new OapiChatSendRequest();
            request.Chatid = chatId;
            request.Msgtype = "action_card";

            OapiChatSendRequest.ActionCardDomain _card = new OapiChatSendRequest.ActionCardDomain();
            _card.Title = Title;
            _card.Markdown = Markdown;
            _card.BtnOrientation = BtnOrientation;
            _card.BtnJsonList = BtnJsonList;
            if (!string.IsNullOrWhiteSpace(agentId))
            {
                _card.Agentid = agentId;
            }
            else
            {
                _card.Agentid = AgentId.ToString();
            }

            request.ActionCard_ = _card;

            OapiChatSendResponse response = SendChatMessage(request);
            return response;
        }

        /// <summary>
        /// 群消息发送
        /// </summary>
        /// <param name="chatId">会话id</param>
        /// <param name="msg">消息</param>
        /// <returns></returns>
        private OapiChatSendResponse SendChatMessage(OapiChatSendRequest request)
        {
             IDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/chat/send");
            OapiChatSendResponse response = client.Execute(request, accessToken);
            return response;
        }

        /// <summary>
        /// 1.8.获取群消息已读人员列表
        /// </summary>
        /// <param name="messageId">发送群消息接口返回的加密消息id</param>
        /// <param name="cursor">分页查询的游标，第一次可以传0，后续传返回结果中的next_cursor的值。当返回结果中，没有next_cursor时，表示没有后续的数据了，可以结束调用</param>
        /// <param name="size">分页查询的大小，最大可以传100</param>
        public OapiChatGetReadListResponse ChatReadList(string messageId, long cursor, long size)
        {
            IDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/chat/getReadList");
            OapiChatGetReadListRequest request = new OapiChatGetReadListRequest();
            request.SetHttpMethod("GET");
            request.MessageId = messageId;
            request.Cursor = cursor;
            request.Size = size;
            OapiChatGetReadListResponse response = client.Execute(request, accessToken);
            return response;
        }
        #endregion

        #region 2.普通消息

        /// <summary>
        /// 2.1.普通消息-发送 文本/图片/文件消息
        /// </summary>
        /// <param name="sender">发送者用户UserId</param>
        /// <param name="cid">个人聊天会话id，并非群消息的会话ID（chatid） 需要通过JSAPI获取</param>
        /// <param name="messageType">只能是文本/图片/文件</param>
        /// <param name="Content">内容</param>
        /// <returns></returns>
        public OapiMessageSendToConversationResponse SendMessage(string sender,string cid, MessageType messageType, string Content)
        { 
            OapiMessageSendToConversationRequest request = new OapiMessageSendToConversationRequest();
            request.Sender=sender;
            request.Cid=cid;
            request.Msgtype = messageType.ToString();

            switch (messageType)
            {
                case MessageType.text:
                    OapiMessageSendToConversationRequest.TextDomain _text = new OapiMessageSendToConversationRequest.TextDomain();
                    _text.Content = Content;
                    request.Text_ = _text;
                    break;
                case MessageType.image:
                    OapiMessageSendToConversationRequest.ImageDomain _image = new OapiMessageSendToConversationRequest.ImageDomain();
                    _image.MediaId = Content;
                    request.Image_ = _image;
                    break;
                case MessageType.file:
                    OapiMessageSendToConversationRequest.FileDomain _file = new OapiMessageSendToConversationRequest.FileDomain();
                    _file.MediaId = Content;
                    request.File_ = _file;
                    break;
                default:
                    break;
            }

            OapiMessageSendToConversationResponse response = SendCommonMessage(request);
            return response;
        }

        /// <summary>
        /// 2.2.普通消息-发送链接消息
        /// </summary>
        /// <param name="sender">发送者UserId</param>
        /// <param name="cid">个人聊天会话id，并非群消息的会话ID（chatid） 需要通过JSAPI获取</param>
        /// <param name="Title">标题</param>
        /// <param name="Text">内容</param>
        /// <param name="MessageUrl">想去链接</param>
        /// <param name="PicUrl">图片</param>
        public OapiMessageSendToConversationResponse SendMessage(string sender, string cid, string Title, string Text, string MessageUrl, string PicUrl)
        {
            OapiMessageSendToConversationRequest request = new OapiMessageSendToConversationRequest();
            request.Sender = sender;
            request.Cid = cid;
            request.Msgtype = "link";

            OapiMessageSendToConversationRequest.LinkDomain _link = new OapiMessageSendToConversationRequest.LinkDomain();
            _link.Title = Title;
            _link.Text = Text;
            _link.MessageUrl = MessageUrl;
            _link.PicUrl = PicUrl;
            request.Link_ = _link;

            OapiMessageSendToConversationResponse response = SendCommonMessage(request);
            return response;
        }

        /// <summary>
        /// 2.3.普通消息-发送Markedown
        /// </summary>
        /// <param name="sender">发送者UserId</param>
        /// <param name="cid">个人聊天会话id，并非群消息的会话ID（chatid） 需要通过JSAPI获取</param>
        /// <param name="Title">标题</param>
        /// <param name="Text">内容</param>
        /// <returns></returns>
        public OapiMessageSendToConversationResponse SendMessage(string sender, string cid, string Title, string Text)
        {
            OapiMessageSendToConversationRequest request = new OapiMessageSendToConversationRequest();
            request.Sender = sender;
            request.Cid = cid;
            request.Msgtype = "markdown";

            OapiMessageSendToConversationRequest.MarkdownDomain _markdown = new OapiMessageSendToConversationRequest.MarkdownDomain();
            _markdown.Title = Title;
            _markdown.Text = Text;
            request.Markdown_ = _markdown;

            OapiMessageSendToConversationResponse response = SendCommonMessage(request);
            return response;
        }

        /// <summary>
        /// 2.4.普通消息-发送OA表单
        /// </summary>
        /// <param name="sender">发送者UserId</param>
        /// <param name="cid">个人聊天会话id，并非群消息的会话ID（chatid） 需要通过JSAPI获取</param>
        /// <param name="MessageUrl">消息详情URL</param>
        /// <param name="PcMessageUrl">PC查看H5页面地址</param>
        /// <param name="Head">头</param>
        /// <param name="Body">内容</param>
        /// <returns></returns>
        public OapiMessageSendToConversationResponse SendMessage(string sender, string cid, string MessageUrl, string PcMessageUrl,
            OapiMessageSendToConversationRequest.HeadDomain Head, OapiMessageSendToConversationRequest.BodyDomain Body)
        {
            OapiMessageSendToConversationRequest request = new OapiMessageSendToConversationRequest();
            request.Sender = sender;
            request.Cid = cid;
            request.Msgtype = "oa";

            OapiMessageSendToConversationRequest.OaDomain _oa = new OapiMessageSendToConversationRequest.OaDomain();
            _oa.MessageUrl = MessageUrl;
            _oa.PcMessageUrl = PcMessageUrl;
            _oa.Head = Head;
            _oa.Body = Body;

            request.Oa_ = _oa;

            OapiMessageSendToConversationResponse response = SendCommonMessage(request);
            return response;
        }

        /// <summary>
        ///  2.5.普通消息-整体跳转卡片
        /// </summary>
        /// <param name="sender">发送者UserId</param>
        /// <param name="cid">个人聊天会话id，并非群消息的会话ID（chatid） 需要通过JSAPI获取</param>
        /// <param name="Title">标题</param>
        /// <param name="Markdown">内容</param>
        /// <param name="SingleTitle">使用整体跳转ActionCard样式时的标题</param>
        /// <param name="SingleUrl">跳转地址</param>
        /// <param name="agentId">应用id，无需输入</param>
        /// <returns></returns>
        public OapiMessageSendToConversationResponse SendMessage(string sender, string cid, string Title, string Markdown, string SingleTitle, string SingleUrl, string agentId)
        {
            OapiMessageSendToConversationRequest request = new OapiMessageSendToConversationRequest();
            request.Sender = sender;
            request.Cid = cid;
            request.Msgtype = "action_card";

            OapiMessageSendToConversationRequest.ActionCardDomain _card = new OapiMessageSendToConversationRequest.ActionCardDomain();
            _card.Title = Title;
            _card.Markdown = Markdown;
            _card.SingleTitle = SingleTitle;
            _card.SingleUrl = SingleUrl;

            request.ActionCard_ = _card;

            OapiMessageSendToConversationResponse response = SendCommonMessage(request);
            return response;
        }

        /// <summary>
        /// 1.7.群消息-独立跳转卡片
        /// </summary>
        /// <param name="sender">发送者UserId</param>
        /// <param name="cid">个人聊天会话id，并非群消息的会话ID（chatid） 需要通过JSAPI获取</param>
        /// <param name="Title">标题</param>
        /// <param name="Markdown">内容</param>
        /// <param name="BtnOrientation">独立跳转按钮排列方式，竖直排列(0)，横向排列(1)</param>
        /// <param name="BtnJsonList">按钮列表</param>
        /// <returns></returns>
        public OapiMessageSendToConversationResponse SendMessage(string sender, string cid, string Title, string Markdown,
            string BtnOrientation,OapiMessageSendToConversationRequest.BtnJsonDomain BtnJsonList)
        {
            OapiMessageSendToConversationRequest request = new OapiMessageSendToConversationRequest();
            request.Sender = sender;
            request.Cid = cid;
            request.Msgtype = "action_card";

            OapiMessageSendToConversationRequest.ActionCardDomain _card = new OapiMessageSendToConversationRequest.ActionCardDomain();
            _card.Title = Title;
            _card.Markdown = Markdown;
            _card.BtnOrientation = BtnOrientation;
            _card.BtnJsonList =new List<OapiMessageSendToConversationRequest.BtnJsonDomain>() { BtnJsonList };
            request.ActionCard_ = _card;

            OapiMessageSendToConversationResponse response = SendCommonMessage(request);
            return response;
        }

        /// <summary>
        /// 发送普通消息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        private OapiMessageSendToConversationResponse SendCommonMessage(OapiMessageSendToConversationRequest request)
        {
            IDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/message/send_to_conversation");
            OapiMessageSendToConversationResponse response = client.Execute(request, accessToken);
            return response;
        }
        #endregion

        #region 3.工作消息
        /// <summary>
        /// 工作通知消息
        /// </summary>
        /// <param name="userIdList">消息接收人Id列表</param>
        /// <param name="msg">消息</param>
        /// <returns></returns>
        private OapiMessageCorpconversationAsyncsendV2Response SendJobMessage(string userIdList, OapiMessageCorpconversationAsyncsendV2Request.MsgDomain msg)
        {
            IDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2");

            OapiMessageCorpconversationAsyncsendV2Request request = new OapiMessageCorpconversationAsyncsendV2Request();
            request.AgentId = AgentId;//应用agentid (应用需要到工作台 https://oa.dingtalk.com/index.htm#/microApp/microAppList 下创建)
            request.UseridList = userIdList;
            request.ToAllUser = false;
            request.Msg_ = msg;
            if (msg.Msgtype.ToLower().Equals("link"))
            {
                //目前官方接口Link类型存在问题,将message_url 替换为messageUrl
                request.Msg = request.Msg.Replace("message_url", "messageUrl");
                request.Msg = request.Msg.Replace("pic_url", "picUrl");
            }
            OapiMessageCorpconversationAsyncsendV2Response response = client.Execute(request, accessToken);
            return response;
        }
 
        /// <summary>
        /// 3.1.发送工作通知消息-文本
        /// </summary>
        /// <param name="userIdList">接收用户Id列表</param>
        /// <param name="Message">消息内容</param>
        /// <returns></returns>
        private OapiMessageCorpconversationAsyncsendV2Response JobMessageSend_Text(string userIdList,string Message)
        {
            OapiMessageCorpconversationAsyncsendV2Request.MsgDomain msg = new OapiMessageCorpconversationAsyncsendV2Request.MsgDomain();
            msg.Msgtype = "text";//消息类型

            //组织Text 消息数据
            OapiMessageCorpconversationAsyncsendV2Request.TextDomain Text = new OapiMessageCorpconversationAsyncsendV2Request.TextDomain();
            Text.Content = Message;//文本消息内容
            msg.Text = Text;

            //发送工作消息
            return SendJobMessage(userIdList, msg);
        }

        /// <summary>
        /// 发送工作通知消息-文本/图片/文件
        /// </summary>
        /// <param name="userIdList"></param>
        /// <param name="messageType"></param>
        /// <param name="content"></param>
        /// <returns></returns>
        public OapiMessageCorpconversationAsyncsendV2Response JobMessageSend(string userIdList, MessageType messageType, string content)
        {
            OapiMessageCorpconversationAsyncsendV2Response _result = null;
            switch (messageType)
            { 
                case MessageType.text:
                    _result= JobMessageSend_Text(userIdList, content);
                    break;
                case MessageType.image:
                    _result = JobMessageSend_Image(userIdList, content);
                    break;
                case MessageType.file:
                    _result = JobMessageSend_File(userIdList, content);
                    break;
                default:
                    break;
            }
            return _result;
        }
        /// <summary>
        /// 3.2.发送工作通知消息-图片
        /// </summary>
        /// <param name="userIdList">用户Id列表</param>
        /// <param name="ImageMediaId">图片MediaId</param>
        /// <returns></returns>
        private OapiMessageCorpconversationAsyncsendV2Response JobMessageSend_Image(string userIdList, string ImageMediaId)
        {
            OapiMessageCorpconversationAsyncsendV2Request.MsgDomain msg = new OapiMessageCorpconversationAsyncsendV2Request.MsgDomain();
            msg.Msgtype = "image";//消息类型

            //组织Image 消息数据
            OapiMessageCorpconversationAsyncsendV2Request.ImageDomain img = new OapiMessageCorpconversationAsyncsendV2Request.ImageDomain();
            img.MediaId = ImageMediaId;
            msg.Image = img;

            //发送工作消息
            return SendJobMessage(userIdList, msg);
        }

        /// <summary>
        /// 3.3.发送工作通知消息-文件
        /// </summary>
        /// <param name="userIdList">用户Id列表</param>
        /// <param name="FileMediaId">文件MediaId</param>
        /// <returns></returns>
        private OapiMessageCorpconversationAsyncsendV2Response JobMessageSend_File(string userIdList, string FileMediaId)
        {
            OapiMessageCorpconversationAsyncsendV2Request.MsgDomain msg = new OapiMessageCorpconversationAsyncsendV2Request.MsgDomain();
            msg.Msgtype = "file";//消息类型

            //组织File 消息数据
            OapiMessageCorpconversationAsyncsendV2Request.FileDomain file = new OapiMessageCorpconversationAsyncsendV2Request.FileDomain();
            file.MediaId = FileMediaId;
            msg.File = file;

            //发送工作消息
            return SendJobMessage(userIdList, msg);
        }

        /// <summary>
        /// 3.4.发送工作通知消息-链接
        /// </summary>
        /// <param name="userIdList">用户Id列表</param>
        /// <param name="Title">消息标题</param>
        /// <param name="Text">消息描述</param>
        /// <param name="MessageUrl">消息点击跳转链接地址</param>
        /// <param name="PicUrl">图片媒体文件id</param>
        /// <returns></returns>
        public OapiMessageCorpconversationAsyncsendV2Response JobMessageSend(string userIdList, MessageType messageType,string Title, string Text, string MessageUrl, string PicUrl)
        {
            OapiMessageCorpconversationAsyncsendV2Request.MsgDomain msg = new OapiMessageCorpconversationAsyncsendV2Request.MsgDomain();
            msg.Msgtype = "link";

            //组织Link 消息数据
            OapiMessageCorpconversationAsyncsendV2Request.LinkDomain link = new OapiMessageCorpconversationAsyncsendV2Request.LinkDomain();
            link.Title = Title;
            link.Text = Text;
            link.MessageUrl = MessageUrl;
            link.PicUrl = PicUrl;
            msg.Link = link;

            //发送工作消息
            return SendJobMessage(userIdList, msg);
        }

        /// <summary>
        /// 3.5.发送工作通知消息-MarkDown格式消息
        /// </summary>
        /// <param name="userIdList"></param>
        /// <param name="Title"></param>
        /// <param name="Text"></param>
        /// <returns></returns>
        public OapiMessageCorpconversationAsyncsendV2Response JobMessageSend(string userIdList, string Title, string Text)
        {
            OapiMessageCorpconversationAsyncsendV2Request.MsgDomain msg = new OapiMessageCorpconversationAsyncsendV2Request.MsgDomain();
            msg.Msgtype = "markdown";

            //组织markdown 消息数据
            OapiMessageCorpconversationAsyncsendV2Request.MarkdownDomain markdown = new OapiMessageCorpconversationAsyncsendV2Request.MarkdownDomain();
            markdown.Title = Title;
            markdown.Text = Text;

            msg.Markdown = markdown;
            //发送工作消息
            return SendJobMessage(userIdList, msg);
        }

        /// <summary>
        /// 3.5.发送工作通知消息-OA格式消息
        /// </summary>
        /// <param name="userIdList">接收用户UserId列表</param>
        /// <param name="MessageUrl">消息点击链接地址</param>
        /// <param name="PcMessageUrl">PC端点击消息时跳转到的H5地址</param>
        /// <param name="Head">消息头</param>
        /// <param name="Body">消息内容</param>
        /// <returns></returns>
        public OapiMessageCorpconversationAsyncsendV2Response JobMessageSend(string userIdList, string MessageUrl, string PcMessageUrl,
            OapiMessageCorpconversationAsyncsendV2Request.HeadDomain Head, OapiMessageCorpconversationAsyncsendV2Request.BodyDomain Body)
        {
            OapiMessageCorpconversationAsyncsendV2Request.MsgDomain msg = new OapiMessageCorpconversationAsyncsendV2Request.MsgDomain();
            msg.Msgtype = "oa";

            //组织OA 消息数据
            OapiMessageCorpconversationAsyncsendV2Request.OADomain oa = new OapiMessageCorpconversationAsyncsendV2Request.OADomain();
            oa.MessageUrl = MessageUrl;//消息点击链接地址
            oa.PcMessageUrl = PcMessageUrl; //PC端点击消息时跳转到的H5地址
            oa.Head = Head;
            oa.Body = Body;

            msg.Oa = oa;
            //发送工作消息
            return SendJobMessage(userIdList, msg);
        }

        /// <summary>
        /// 3.5.发送工作通知消息-整体跳转卡片
        /// </summary>
        /// <param name="userIdList">接收用户UserId列表</param>
        /// <param name="Title">标题</param>
        /// <param name="Markdown">消息内容</param>
        /// <param name="SingleTitle">使用整体跳转ActionCard样式时的标题</param>
        /// <param name="SingleUrl">消息点击链接地址</param>
        /// <returns></returns>
        public OapiMessageCorpconversationAsyncsendV2Response JobMessageSend(string userIdList,string Title, string Markdown, string SingleTitle, string SingleUrl)
        {
            OapiMessageCorpconversationAsyncsendV2Request.MsgDomain msg = new OapiMessageCorpconversationAsyncsendV2Request.MsgDomain();
            msg.Msgtype = "action_card";

            //组织action_card 消息数据
            OapiMessageCorpconversationAsyncsendV2Request.ActionCardDomain action = new OapiMessageCorpconversationAsyncsendV2Request.ActionCardDomain();
            action.Title = Title;
            action.Markdown = Markdown;
            action.SingleTitle = SingleTitle;
            action.SingleUrl = SingleUrl;

            msg.ActionCard = action;
            //发送工作消息
            return SendJobMessage(userIdList, msg);
        }

        /// <summary>
        /// 3.6.发送工作通知消息-独立跳转卡片
        /// </summary>
        /// <param name="userIdList">接收用户UserId列表</param>
        /// <param name="Title">标题</param>
        /// <param name="Markdown">消息内容</param> 
        /// <param name="BtnOrientation">独立跳转按钮排列方式，竖直排列(0)，横向排列(1)</param>
        /// <param name="BtnJsonList">独立跳转时的按钮列表</param>
        /// <returns></returns>
        public OapiMessageCorpconversationAsyncsendV2Response JobMessageSend(string userIdList, string Title, string Markdown,
            string BtnOrientation, List<OapiMessageCorpconversationAsyncsendV2Request.BtnJsonListDomain> BtnJsonList)
        {
            OapiMessageCorpconversationAsyncsendV2Request.MsgDomain msg = new OapiMessageCorpconversationAsyncsendV2Request.MsgDomain();
            msg.Msgtype = "action_card";

            //组织action_card 消息数据
            OapiMessageCorpconversationAsyncsendV2Request.ActionCardDomain action = new OapiMessageCorpconversationAsyncsendV2Request.ActionCardDomain();
            action.Title = Title;
            action.Markdown = Markdown;
            action.BtnOrientation = BtnOrientation;
            action.BtnJsonList = BtnJsonList;

            msg.ActionCard = action;
            //发送工作消息
            return SendJobMessage(userIdList, msg);
        }
        #endregion
    }
}
